<?php
/**
 * 内容管理视图
 *
 *
 *
 */
// 排序
$arr_orderby    = array(
    'id'        => '&orderby=id',
    );

// 保存数据框架名
$save_frame = $_SESSION[$G_admin_session_key]['save_frame'];
$back_url   = get_current_url();
// 将当前URL保存在Cookie中，避免复杂的URL字符串
cookie('back_url', strcode($back_url));
$url_cur    = get_current_url(array('orderby', 'desc'));

$tbl_zone   = $_TABLES['city'];
$conn       = & get_db_conn();
$sql1="SELECT * FROM $tbl_zone ORDER BY num asc";
$rs = & $conn->GetAll($sql1);
/**
 * 搜索参数处理
 *
 */
// 关键字
$key            = trim(@$_GET['key']);

if(isset($_GET['num']))$num            = trim(@$_GET['num']);
else $num            =-1;
$num1            = trim(@$_GET['num1']);
$num2            = trim(@$_GET['num2']);
$is_ad      = @(int)$_GET['is_ad'];

$dsp_ad     = ($is_ad == 1) ? 'style="display:block"':'style="display:none"';

// + -------------------------------------- + //

require($abs_admin_cppath . '/header.php');
?>
<SCRIPT LANGUAGE="JavaScript" SRC="<?php echo $url_global['common']; ?>/js/popcalendar.js"></SCRIPT>
<script>
<?php if($city){?>
    var url	= '<?php echo $G_web_root;?>/common/getcity.php?city=510000&sel=<?php echo $city;?>';
	$.get(url,function(data){
			$("#city").html(unescape(data));
	});
<?php
}else{
    ?>
    var url	= '<?php echo $G_web_root;?>/common/getcity.php?city=510000';
	$.get(url,function(data){
			$("#city").html(unescape(data));
	});
    <?php
}

?>
</script>
<div class="spH10"></div>

<div class="datacontainer1" id="listDiv">
<form action="<?php echo $mod_url['li'] ?>" name="search" method="get">
<div class="new_line">
<input type="hidden" name="mod" value="<?php echo $mod ?>">
<input type="hidden" name="action" value="<?php echo $action ?>">
<input type="hidden" name="cata" value="<?php echo $cata ?>">



	<div class="spW10 fl"></div>
	<div style="display:block;clear:both">
	<a href="<?php echo $mod_url['add'] ?>"  class="btn fl">新增地区信息</a>
	&nbsp;&nbsp;
    
    <select name="num" onchange="changenum(this.value,'num','num1')">
        <option value="-1" selected="true">请选择</option>
		<option value="0"  <?php if($num==0){?>selected="true"<?php }?>>一级地区</option>
	</select>
    <select name="num1" id="num1" onchange="changenum(this.value,'num1','num2')">
		<option value="0"  selected="true">请选择</option>
		<?php
		if($rs&&$num==0) {
			foreach($rs as $article) {
				if($article['num']==0&&$article['num1']==0){
				?>
				<option value="<?php echo $article['id'];?>" <?php if($num1==$article['id']){echo ' selected="true"';}?>><?php echo $article['cname'];?></option>
				<?php
				}
			}
		}?>
	</select>
    <select name="num2" id="num2">
		<option value="0"  selected="true">请选择</option>
		<?php
		if($rs&&$num1!=0) {
			foreach($rs as $article) {
				if($article['num']!=0&&$article['num1']==0&&$article['num']==$num1){
				?>
				<option value="<?php echo $article['id'];?>" <?php if($num2==$article['id']){echo ' selected="true"';}?>><?php echo $article['cname'];?></option>
				<?php
				}
			}
		}?>
	</select>
        
    &nbsp;&nbsp;
    <input type="text" name="key" value="<?php echo $key ?>" size="10" class="text" >
	<input type="submit" value="查询" class="btn">
</div>
</div>
</form>
<form action="<?php echo $mod_url['del'] ?>" name="items_form" method="post" target="<?php echo $save_frame?>" onsubmit="return submit_select_items(this.name, 'item_id[]');">
<TABLE BORDER="0" CELLPADDING="4" CELLSPACING="1" width="100%" class="list_table">
<THEAD>
	<TR class="list_head">
		<TH scope=col width="30">#</TH>
		<TH scope=col>名称</TH>
        <TH scope=col>上级地区</TH>
		<TH scope=col width="100">操作</TH></TR></THEAD>
<TBODY>
<?php
$tr_class   = '';
if(!empty($viewvar['record']) && sizeof($viewvar['record']) > 0) {
    $tbl_mem    = $_TABLES['city'];
    $conn   = & get_db_conn();
    foreach($viewvar['record'] as $k=>$v) {
        $id  = $v['id'];
        $tr_class   = $tr_class != 'tr0' ? 'tr0' : 'tr1';
        $title_full = htmlspecialchars($v['cname']);
        if($v['num']==0&&$v['num1']==0){
            $place='一级地区';
        }elseif($v['num']!=0&&$v['num1']==0){
            $sql="select * from $tbl_mem where id={$v['num']}";
            $view_var1   = $conn->GetRow($sql);
            $place='一级地区 => '.$view_var1['cname'];
        }elseif($v['num']!=0&&$v['num1']!=0){
            $sql="select * from $tbl_mem where id={$v['num']}";
            $view_var1   = $conn->GetRow($sql);
            $sql="select * from $tbl_mem where id={$v['num1']}";
            $view_var2   = $conn->GetRow($sql);
            $place='一级地区 => '.$view_var1['cname'].' => '.$view_var2['cname'];
        }
?>
	<TR class="<?php echo $tr_class; ?>" onmouseover="return chgBg(this, 1);" onmouseout="return chgBg(this, 0);">
		<TD width="30" class="textC"><input type="checkbox" value="<?php echo $v['id']; ?>" name="item_id[]"></TD>
		<TD>&nbsp;<?php echo $title_full;?></TD>
        <TD>&nbsp;<?php echo $place;?></TD>
		<TD width="100">
			<a href="<?php echo $mod_url['modify'] ?>&id=<?php echo $v['id']; ?>" class="btn_modify fl" title="修改内容">修改</a> 
			<a href="<?php echo $mod_url['del'] ?>&item_id=<?php echo $v['id']; ?>" target="<?php echo $save_frame; ?>" onclick="return del_this();" class="btn_del fl" title="删除内容">删除</a>
		</TD></TR>
<?php
    }
} else {
?>
<TR class="tr0" onmouseover="return chgBg(this, 1);" onmouseout="return chgBg(this, 0);">
<TD colspan="6">没有或没有找到合适的记录！</td>
</td>
<?php
}
?>
</TBODY>
</TABLE>
<?php
// 分页
$page_info  = $viewvar['record_total'] . '条记录 共' . $viewvar['page_total'] . '页';
$page_list  = get_page_nav($viewvar['page_total']);
?>
<script>
function changenum(va,type,id){
    var op='<option value="0" >请选择</option>';
    if((type=='num'&&va!=-1)||(type=='num1'&&va!=0)){
        url = '<?php echo $G_web_root.'/common/ajax.php?action=getCity';?>';//window.location.href=url+'&cid='+va+'&num=1&noid=<?php echo $record['id'];?>';
	    $.post(url, {cid:va,num:1},function(data){
	       if(data['type']==1){
	           for(var i in data['data']){
	               if(data['data'][i]['id']){
	                   op+='<option value="'+data['data'][i]['id']+'">'+data['data'][i]['cname']+'</option>';
                   }
               }
	       }
           $('#'+id).html(op);
	    },'json');
    }else{
        $('#'+id).html(op);
    }
}
</script>
<div class="page_nav">
	<div class="page_info">
		<?php echo $page_info ?>
	</div>
	<div class="page_list_pre">
		&nbsp;&nbsp;<a href="javascript:void(0);" onclick="chkbox_sel_all('items_form', 'item_id[]');"><B>全选</B></a> <a href="javascript:void(0);" onclick="chkbox_sel_reverse('items_form', 'item_id[]');"><B>反选</B></a>
	</div>
	<div class="page_list">
		<?php echo $page_list?>
	</div>
</div>
<div class="new_line">
<input type="submit" name="del" value="删除" class="btn fl">
<input type="hidden" name="deltype" value="<?php echo $save_flag; ?>">

</div>
</form>
		</div>
</div>

<?php
require($abs_admin_cppath . '/footer.php');
?>